<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./js/moment-with-locales.js"></script>
    <script>
      // duration
      console.log(
        moment.duration(),
        moment.duration(100),
        moment.duration(2, "seconds"),
        moment.duration(3, "minutes"),
        moment.duration(3, "M"),
        moment.duration({
          days: 1,
          hours: 2,
          milliseconds: 3,
          minutes: 4,
          months: 5,
          seconds: 6,
          years: 7,
        }),
        moment.duration("23:59:59")
      );

      const d1 = moment.duration();
      const d2 = d1.clone();
      d1.add(1, "second");
      console.log(d1, d2);

      moment.locale("zh-cn");
      // humanize(): 人性化
      console.log(moment.duration(1, "minutes").humanize());

      // milliseconds()
      console.log(
        moment.duration(500).milliseconds(),
        moment.duration(1500).milliseconds(), // 会计算进位
        moment.duration(1500).asMilliseconds() // 不会计算
      );

      // add()
      var a = moment.duration(1, "d");
      var b = moment.duration(2, "d");
      a.add(b).days();
      console.log(a);

      //  moment.duration(x.diff(y))
      a = moment([2018, 10, 21, 10, 05]);
      b = moment([2018, 10, 21, 10, 06]);
      console.log(moment.duration(b.diff(a)));

      // as, get
      console.log(
        moment.duration(1000).as("milliseconds"),
        moment.duration(1000).as("seconds")
      );

      b = moment.duration({
        days: 1,
        hours: 2,
        milliseconds: 3,
        minutes: 4,
        months: 5,
        seconds: 6,
        years: 7,
      });
      console.log(b.get("days"));
    </script>
  </body>
</html>
